home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2004 April / Gamestar_61_2004-04_dvdb.iso / DVDStar / Editace / hltp.exe / {app} / Applications / QuArK / plugins / mapchecks.py < prev    next >
Text File  |  2004-01-05  |  4KB  |  123 lines

  1. """   QuArK  -  Quake Army Knife
  2.  
  3. Basic map validity checking
  4. """
  5. #
  6. # Copyright (C) 1996-99 Armin Rigo
  7. # THIS FILE IS PROTECTED BY THE GNU GENERAL PUBLIC LICENCE
  8. # FOUND IN FILE "COPYING.TXT"
  9. #
  10.  
  11. #$Header: /cvsroot/quark/runtime/plugins/mapchecks.py,v 1.5 2003/12/17 13:58:59 peter-b Exp $
  12.  
  13.  
  14.  
  15. Info = {
  16.    "plug-in":       "Basic Checks",
  17.    "desc":          "Basic map validity checking.",
  18.    "date":          "26 dec 98",
  19.    "author":        "Armin Rigo",
  20.    "author e-mail": "arigo@planetquake.com",
  21.    "quark":         "Version 5.3" }
  22.  
  23.  
  24. import quarkx
  25. from quarkpy.maputils import *
  26. import quarkpy.qmenu
  27. import quarkpy.mapsearch
  28.  
  29.  
  30.  
  31. def BasicCheck(menu=None):
  32.     editor = mapeditor(SS_MAP)
  33.     if editor is None: return
  34.     err = {}
  35.     errobj = []
  36.  
  37.     if editor.Root.name != "worldspawn:b":
  38.         err["The top-level entity of the map should be called 'worldspawn'."] = 0
  39.         errobj = errobj + [editor.Root]
  40.     else:
  41.         test = editor.Root.findallsubitems("worldspawn", ':b')[1:]    # ignore the top-level one
  42.         if len(test):
  43.             err["Only one 'worldspawn' is allowed in the map."] = 0
  44.             errobj = errobj + test
  45.  
  46.     test = editor.Root.findallsubitems("info_player_start", ':e')
  47.     if len(test)==0:
  48.         if quarkx.setupsubset()["Code"] < "a":   # ignore the error in Quake 3 mode
  49.             err["The map must contain at least one info_player_start."] = 0
  50.     elif len(test)>1:
  51.         err["The map should not contain several info_player_start."] = 0
  52.         errobj = errobj + test
  53.  
  54.     test = editor.Root.findallsubitems("", ':b')
  55.     for obj in test:
  56.         if len(obj.findallsubitems("", ':p'))==0:
  57.             err["Brush entities (e.g. doors and plats) are not valid without any attached polyhedron. Delete these empty entities in the tree view now or the game will crash."] = 0
  58.             errobj.append(obj)
  59.  
  60.     import quarkpy.mapholes
  61.     watery = quarkpy.mapholes.WateryChecker(editor)
  62.     test = editor.Root.listpolyhedrons
  63.     for obj in test:
  64.         f = obj.faces
  65.         for face in f:
  66.             texp = face.threepoints(0)
  67.             if texp is not None:
  68.                 texpt0 = texp[1]-texp[0]
  69.                 texpt1 = texp[2]-texp[0]
  70.                 #
  71.                 # The limit 273.1 is just a bit larger than what TXQBSP allows;
  72.                 # it would be 1E-6 if texpt0 and texpt1 where scaled down by a factor 128.
  73.                 #
  74.                 if abs((texpt0*texpt0)*(texpt1*texpt1)-(texpt0*texpt1)*(texpt0*texpt1)) < 273.1:
  75.                     err["The scale of some textures is too small, or the textures are completely distorted."] = 0
  76.                     errobj.append(face)
  77.         w = not watery(face)
  78.         for face in f[:-1]:
  79.             if (not watery(face)) != w:
  80.                 err["Cannot mix watery and non-watery textures on a polyhedron."] = 0
  81.                 errobj.append(obj)
  82.                 break
  83.         else:
  84.             if not w:
  85.                 w = obj.faces[0].texturename
  86.                 for face in obj.faces[1:]:
  87.                     if w != face.texturename:
  88.                         err["Cannot mix different watery textures on the same polyhedron."] = 0
  89.                         errobj.append(obj)
  90.                         break
  91.  
  92.     if err != {}:
  93.         return quarkpy.mapsearch.problem("\n".join(err.keys()), errobj)
  94.     else:
  95.         return quarkpy.mapsearch.noproblem(menu)
  96.  
  97.  
  98.  
  99. #--- add the new menu item into the "Search" menu ---
  100.  
  101. Basic1 = quarkpy.qmenu.item("&Basic checks", BasicCheck, "|Basic checks:\n\nThis function performs various checks on your map, to see if it can be compiled correctly, and function properly.", "intro.mapeditor.menu.html#searchmenu")
  102. quarkpy.mapsearch.checkitems.append(Basic1)
  103.  
  104.  
  105. # ----------- REVISION HISTORY ------------
  106. #
  107. #
  108. # $Log: mapchecks.py,v $
  109. # Revision 1.5  2003/12/17 13:58:59  peter-b
  110. # - Rewrote defines for setting Python version
  111. # - Removed back-compatibility with Python 1.5
  112. # - Removed reliance on external string library from Python scripts
  113. #
  114. # Revision 1.4  2003/03/21 05:47:45  cdunde
  115. # Update infobase and add links
  116. #
  117. # Revision 1.3  2000/06/03 10:25:30  alexander
  118. # added cvs headers
  119. #
  120. #
  121. #
  122. #
  123.